package xin.cymall.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import xin.cymall.utils.DateUtil;
@RestController
@RequestMapping("/excel")
public class ExcelController extends AbstractController{
	@RequestMapping("/downloadExcel")
	public void downloadExcel(HttpServletRequest request,HttpServletResponse response) throws IOException {
		response.setContentType("multipart/form-data");
		String fileWriteTime = DateUtil.getYmdhmsFName();
		response.setHeader("Content-Disposition", "attachment;filename="+fileWriteTime+".xls");
		OutputStream out = response.getOutputStream();  
		String path = request.getParameter("path");
		File file = new File(path);
		InputStream in = new FileInputStream(file);  
		int b;  
		while((b=in.read())!=-1){  
		    out.write(b);  
		}  
		in.close();  
		out.close();
		file.delete();
	}
}
